import React, { useState, useEffect, useRef } from 'react';
//
import { Row, Col, Card, Tabs, Descriptions, Divider, message,Collapse} from 'antd';


import {alarmcode} from '@/utils/alarmcode-enum';

import styles from './index.less';

// import styles from '@/pages/monitoring/details/index.less';


interface rundateProps {

  runningData:any;
  type:number;
}




  const RunData: React.FC<rundateProps> = (props) => {
    const { runningData,type} = props;
  const getRunningDataDom = function () {
    if (type==1) {
      return (  <Row gutter={16} key={5}>
        <Col span={4}>
          <Card className={styles.itemCard} title="运行状态" headStyle={{ border: 0 }}>
            <p>正转：{runningData?.fwc==1?'是':'否'}</p>
            <p>反转：{runningData?.fwc==1?'是':'否'}</p>
            <p>停止：{runningData?.stop==1?'是':'否'}</p>
          </Card>
        </Col>
        <Col span={4}>
          <Card className={styles.itemCard} title="故障" headStyle={{ border: 0 }}>
          
            <p>poff：{runningData?.poff==1?'是':'否'}</p>
            <p>故障状态：{runningData?.alarm==1?'是':'否'}</p>
            {runningData?.alarm!=0?<p>故障原因：{alarmcode[runningData?.alarmCode]}故障</p>:null}
            {/* <p>跳闸（脱扣）状态：{runningData?.trip==1?'是':'否'}</p>
            {runningData?.tripCode!=0?<p>跳闸原因：{alarmcode[runningData?.tripCode]}故障</p>:null} */}
          </Card>
        </Col>
        <Col span={4}>
          <Card className={styles.itemCard} title="运行数据" headStyle={{ border: 0 }}>
            <p>运行频率：{runningData?.operatingFrequency}Hz</p>
            <p>设定频率：{runningData?.settingFrequency}Hz</p>
            <p>母线电压：{runningData?.busVoltage}V</p>
            <p>运行转速：{runningData?.rotationalVelocity}RPM</p>
        
          </Card>
        </Col>
        <Col span={4}>
          <Card className={styles.itemCard} title="运行数据" headStyle={{ border: 0 }}>
            <p>输出电压：{runningData?.outputVoltage}V</p>
            <p>输出电流：{runningData?.outputCurrent}A</p>
            <p>输出功率：{runningData?.outputPower}%</p>
            <p>输出转矩：{runningData?.outputTorque}RPM</p>
          </Card>
        </Col>
        <Col span={4}>
          <Card className={styles.itemCard} title="闭环" headStyle={{ border: 0 }}>
            <p>闭环设定:{runningData?.closedLoopSetting}%</p>
            <p>闭环反馈:{runningData?.closedLoopFeedback}%</p>
          </Card>
        </Col>
       
      </Row>);
    } else if (type==4) {
      return (  <Row gutter={16} key={5}>
        <Col span={4}>
          <Card className={styles.itemCard} title="运行状态" headStyle={{ border: 0 }}>
            <p>组合有功总电能：{runningData?.composeTotalActiveEnergy}kWh</p>
            <p>正向有功总电能：{runningData?.forwardTotalActiveEnergy}kWh</p>
            <p>反向有功总电能：{runningData?.reverseTotalActiveEnergy}kWh</p>
           
          </Card>
        </Col>
       
      </Row>);
    } else  {
      // return (<Tooltip placement="topLeft" title="请下载文件到本地使用第三方工具预览"> <a target="_blank" href={"http://localhost:8080/fsmsapi/drawing/download/" + record.drawingId}>{record.title}</a></Tooltip>);
      return (  <Row gutter={16} key={5}>
        <Col span={4}>
          <Card className={styles.itemCard} title="总数据" headStyle={{ border: 0 }}>
            <p>总启动次数:{runningData?.totalStart}</p>
            <p>总跳闸次数：{runningData?.totalTrip}</p>
            <p>累计运行时间：{runningData?.totalRuningHour}</p>
            <p>本次运行时间：{runningData?.currentRuningHour}</p>
          </Card>
        </Col>
        <Col span={4}>
          <Card className={styles.itemCard} title="运行状态" headStyle={{ border: 0 }}>
            <p>运行：{runningData?.running==1?'是':'否'}</p>
            <p>起动：{runningData?.start==1?'是':'否'}</p>
            <p>起动A：{runningData?.startaRunningFlag==1?'是':'否'}</p>
            <p>起动B：{runningData?.startbRunningFlag==1?'是':'否'}</p>
          </Card>
        </Col>
        <Col span={4}>
          <Card className={styles.itemCard} title="报警" headStyle={{ border: 0 }}>
            <p>报警：{runningData?.alarm==1?'是':'否'}</p>
            {runningData?.alarm!=0?<p>报警原因：{alarmcode[runningData?.alarmCode]}报警</p>:null}
            <p>跳闸（脱扣）：{runningData?.trip==1?'是':'否'}</p>
            {runningData?.tripCode!=0?<p>跳闸原因：{alarmcode[runningData?.tripCode]}故障</p>:null}
          </Card>
        </Col>
        <Col span={4}>
          <Card className={styles.itemCard} title="电流" headStyle={{ border: 0 }}>
            <p>A相电流：{runningData?.phaseaCurrent}A</p>
            <p>B相电流：{runningData?.phasebCurrent}A</p>
            <p>C相电流：{runningData?.phasecCurrent}A</p>
            <p>电流不平衡率：{runningData?.currentUnbalance}%</p>
          </Card>
        </Col>
        <Col span={4}>
          <Card className={styles.itemCard} title="线电压" headStyle={{ border: 0 }}>
            <p>线电压Uab：{runningData?.uabLineVoltage}V</p>
            <p>线电压Ubc：{runningData?.ubcLineVoltage}V</p>
            <p>线电压Uca：{runningData?.ucaLineVoltage}V</p>
            <p>热容量百分比:{runningData?.heatCapacityPercentage}</p>
          </Card>
        </Col>
        <Col span={4}>
          <Card className={styles.itemCard} title="功率" headStyle={{ border: 0 }}>
            <p>有功功率P：{runningData?.activePower}kW</p>
            <p>无功功率Q：{runningData?.reactivePower}kvar </p>
            <p>视在功率S：{runningData?.apparentPower}kVA</p>
            <p>功率因数cosΦ：{runningData?.powerFactor}</p>
          </Card>
        </Col>
      </Row>);
    }
  }

  return (
  
    <div className={styles.rundata}>
       <Row  style={{ padding: '0 0 16px 0', color: '#fff' }} key={4}>
        <Col span={24}>数据更新时间：{runningData?.acquisitionTime} </Col>
      </Row>
      {getRunningDataDom()} 
    </div>
  );
};

export default RunData;
